package com.zhuiyun.educations.api.fileprice.service.impl;

import com.github.pagehelper.PageHelper;
import com.zhuiyun.educations.api.fileprice.entity.FilePrice;
import com.zhuiyun.educations.api.fileprice.mapper.FilePriceMapper;
import com.zhuiyun.educations.api.fileprice.service.FilePriceService;
import com.zhuiyun.educations.common.response.CommonResult;
import com.zhuiyun.educations.util.pageUtil.MybatisPageHelper;
import com.zhuiyun.educations.util.pageUtil.PageRequest;
import com.zhuiyun.educations.util.pageUtil.PageResult;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @ClassName CoursePriceServiceImpl
 * @Description TODO 课程价钱管理
 * @Author ys
 * @Date 2023/6/19 19:45
 **/
@Service
public class FilePriceServiceImpl implements FilePriceService {
    @Resource
    private FilePriceMapper filePriceMapper;
    /**
     * @Author ys
     * @Description TODO 分页查询
     * @Date 2023/6/26 14:09
     * @Return CommonResult
     * @param
     */
    @Override
    public CommonResult getFilePrice(PageRequest pageRequest) {
        PageHelper.startPage(pageRequest);
        PageResult pageResult = MybatisPageHelper.getPageResult(filePriceMapper.getFilePrice(pageRequest));
        return CommonResult.ok(pageResult);
    }
    /**
     * @Author ys
     * @Description TODO 新增
     * @Date 2023/6/26 14:09
     * @Return CommonResult
     * @param
     */
    @Override
    public CommonResult addFilePrice(FilePrice filePrice) {
        Date date =  new Date();
        filePrice.setDelFlag("0");
        filePrice.setCreateTime(date);
        filePrice.setUpdateTime(date);
        return CommonResult.ok(filePriceMapper.insertSelective(filePrice));
    }
    /**
     * @Author ys
     * @Description TODO 修改
     * @Date 2023/6/26 14:09
     * @Return CommonResult
     * @param
     */
    @Override
    public  CommonResult updateFilePrice(FilePrice filePrice) {
        Date date =  new Date();
        filePrice.setUpdateTime(date);
        return CommonResult.ok(filePriceMapper.updateByPrimaryKeySelective(filePrice));
    }
    /**
     * @Author ys
     * @Description TODO 逻辑删除
     * @Date 2023/6/26 14:09
     * @Return CommonResult
     * @param
     */
    @Override
    public CommonResult deleteFilePriceById(int id) {
        return CommonResult.ok(filePriceMapper.deleteFilePriceById(id));
    }
    /**
     * @Author ys
     * @Description TODO 资料下拉
     * @Date 2023/6/26 14:09
     * @Return CommonResult
     * @param
     */
    @Override
    public CommonResult fileSelect() {
        return  CommonResult.ok(filePriceMapper.fileSelect());
    }

}
